package utils;

public class AreaUtils {

    /**
     * 已知三个点坐标，求三角形面积
     * @param x1
     * @param y1
     * @param x2
     * @param y2
     * @param x3
     * @param y3
     * @return 三角形面积
     */
    public static double area(double x1,double y1,double x2,double y2,double x3,double y3){
        double result = 0.5 * Math.abs((x2-x1)*(y3-y1)-(x3-x1)*(y2-y1));
        return result;
    }

    /**
     * 已经矩形四个顶点坐标和一个点的坐标，判断该点是否在矩形内。
     * @param x1
     * @param y1
     * @param x2
     * @param y2
     * @param x3
     * @param y3
     * @param x4
     * @param y4
     * @param x 要判断的点的横坐标
     * @param y 要判断的点的纵坐标
     * @return
     */
    public static boolean isInner(double x1,double y1,
                                  double x2,double y2,
                                  double x3,double y3,
                                  double x4,double y4,
                                  double x,double y){
        double area1 = AreaUtils.area(x1,y1,x2,y2,x,y);
        double area2 = AreaUtils.area(x2,y2,x3,y3,x,y);
        double area3 = AreaUtils.area(x3,y3,x4,y4,x,y);
        double area4 = AreaUtils.area(x4,y4,x1,y1,x,y);
        double sumArea = area1+area2+area3+area4;
        double rectangleArea = AreaUtils.area(x1,y1,x2,y2,x3,y3)*2;
        if (sumArea==rectangleArea){
            return true;
        }else {
            return false;
        }
    }
}
